/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : adapter.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-03-18 init v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: g++ -Wl,--no-as-needed -std=c++11 adapter.cc
********************************************************************************
*/
#include <iostream>

using namespace std;

/* Connect Usb port */
class CUsbDisk
{
public:
    virtual ~CUsbDisk() {}

    virtual void ConnectDevice()
    {
        cout << "Connect usb port." << endl;
    }
};

/* Connect Type-C port */
class CTypeCInterface
{
public:
    virtual ~CTypeCInterface() {}

    void ConnectDevice()
    {
        cout << "Connect Type-C port." << endl;
    }
};

/* Usb device connect phone */
class CAdapter : public CUsbDisk
{
public:
    CAdapter()
    {
        mpAdaptee = new CTypeCInterface();
    }

    ~CAdapter()
    {
        if (NULL != mpAdaptee) {
            delete mpAdaptee;
        }
    }

    void ConnectDevice()
    {
        if (NULL != mpAdaptee) {
            mpAdaptee->ConnectDevice();
        } else {
            cout << "Adapter abnormal. Connect fail!" << endl;
        }
    }

private:
    CTypeCInterface *mpAdaptee;
};


int main(int argc, char *argv[])
{
    CUsbDisk *theDisk = new CAdapter();

    theDisk->ConnectDevice();

    delete theDisk;
    return 0;
}
